package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.PlanItem;
import com.eling.elcms.travel.model.view.AlliancePlanItemGridView;
import com.eling.elcms.travel.model.view.AlliancePlanItemSaveView;
import com.eling.elcms.travel.service.IPlanItemManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class PlanItemController extends BaseFormController{

	@Autowired
	private IPlanItemManager itemManager;
	
	@RequestMapping("/api/planitem/save")
    @ResponseBody
	public PlanItem save(@ModelAttribute@ModelFilling PlanItem data){
		return itemManager.save(data);
	}
	
	@RequestMapping("/api/planitem/query")
    @ResponseBody
	public List<PlanItem> query(@ModelAttribute PlanItem item){
		return itemManager.query(item);
	}
	
	@RequestMapping("/api/planitem/search*")
	@ResponseBody
	public List<PlanItem> search(@ModelAttribute SearchCondition sc,@ModelAttribute PlanItem item){
		sc.setQueryCondition(item);
		return itemManager.search(sc);
	}
	
	@RequestMapping("/api/planitem/updata")
	@ResponseBody
	public PlanItem updata(@ModelAttribute PlanItem item,@RequestParam(value="pkServicePoint") Long pkServicePoint){
		return itemManager.updata(item,pkServicePoint);
	}

	/**
	 * 保存联盟团信息
	 * @param view
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/planitem/savealliance")
	@ResponseBody
	public Msg saveAlliancePlanItem(@ModelAttribute AlliancePlanItemSaveView view){
		itemManager.saveAlliancePlanItem(view);
		return new Msg("保存成功");
	}
	
	/**
	 * 查询联盟团信息
	 * @param view
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/planitem/queryalliance")
    @ResponseBody
	public List<AlliancePlanItemGridView> queryAlliancePlanItem(@ModelAttribute AlliancePlanItemGridView view){
		return itemManager.queryAlliancePlanItem(view);
	}
}
